<template>

    <DoctorSearch @add-doctor="handleAddDoctor" @search="handleSearch" @export="handleExport" />
    <DoctorForm ref="doctorFormRef" :search-params="searchParams" @view-detail="handleViewDetail" @edit="handleEdit" />

</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import DoctorForm from './DoctorTable.vue'
import DoctorSearch from './DoctorSearch.vue'

// 路由实例
const router = useRouter()

// 搜索参数
const searchParams = ref({})

// 表格组件引用
const doctorFormRef = ref()

// 处理新增医生
const handleAddDoctor = () => {
    console.log('新增医生 - 跳转到新增页面')
    // 路由跳转到新增医生页面
    router.push('/data/doctor/add')
}

// 处理搜索
const handleSearch = (params: any) => {
    // searchParams.value = params
    // 触发表格刷新
    if (doctorFormRef.value) {
        doctorFormRef.value.searchDoctors({
            ...params
        })
    }
}

// 处理导出
const handleExport = () => {
    console.log('导出数据')
    // TODO: 实现导出功能
}

// 处理查看详情
const handleViewDetail = (row: any) => {
    console.log('查看医生详情 - 跳转到详情页面:', row)
    // 路由跳转到医生详情页面，传递医生ID
    router.push(`/data/doctor/detail/${row._id}`)
}

// 处理编辑医生
const handleEdit = (row: any) => {
    console.log('编辑医生 - 跳转到编辑页面:', row)
    // 路由跳转到编辑医生页面，传递医生ID
    router.push(`/data/doctor/update/${row._id}`)
}
</script>

<style scoped></style>